<template>
	<!-- 认领企业 -->
	<view>
		<!-- 菜单 -->
		<view class="top-warp">
			<me-tabs v-model="tabIndex" :tabs="tabs" @change="tabChange"></me-tabs>
		</view>
		
		<!-- 搜索 -->
		<view class="search-bar">
			<u-search placeholder="请输入搜索关键字" v-model="keyword" height="80" bg-color="#fff" shape="round"
				:show-action="false" @search="search"></u-search>
		</view>
		
		<!-- 内容 -->
		<mescroll-uni :top="top" :bottom="bottom" ref="mescrollRef" @init="mescrollInit" :down="downOption"
				@down="downCallback" :up="upOption" @up="upCallback">
			<view class="text-card-list" v-for="(item,index) in dataList" :key="index">
				<qiyexinxi-card2 v-bind="item" @myEvent="refresh"></qiyexinxi-card2>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
	
	import config from "@/app.config.js";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 下拉刷新和上拉加载的组件
		data() {
			return {
				tabs: [{name:'待认领'}, {name:'已认领'}],
				tabIndex: 0, // tab下标
				type:0,
				keyword: '',
				dataList:[],
				query: {
					companyName: '',
					expertIds: vk.getVuex('$user.userInfo.userId'),
					status: '',
					sortBy: 'b.RIQI',
					sortOrder: 'DESC',
					pageNum: 1, //翻页由mescroll组件处理，这里只用于传后台
					pageSize: 10, //翻页由mescroll组件处理，这里只用于传后台
				},
				top: 140,
				bottom: 0,
				downOption: {
					auto: false, //是否在初始化后,自动执行上拉回调callback; 默认true
				},
				upOption: {
					auto: false, //是否在初始化后,自动执行上拉回调callback; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 5 // 每页数据的数量
					},
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
					textNoMore: '没有更多数据',
					empty: {
						tip: '~ 搜索无结果 ~', // 提示
						btnText: ''
					}
				},
			}
		},
		onLoad(options) {
			this.initPage(options);
		},
		onShow() {
			this.refresh();
		},
		methods: {
			refresh(){
				this.mescroll && this.mescroll.resetUpScroll();
			},
			// 页面初始化
			initPage(options = {}){
				checkUpdate();
				
				if(!this.$util.getToken()){
					this.$util.toLogin(()=>this.initPage())
				}else{
					this.$nextTick(() => {
						this.refresh();
					})
				}
			},
			pageTo(path){
				vk.navigateTo(path);
			},
			// 切换菜单
			tabChange() {
				this.dataList = [];  // 先置空列表,显示加载进度
				this.mescroll.resetUpScroll();  // 再刷新列表数据
			},
			upCallback(page) {
				this.query.pageNum = page.num;
				this.query.pageSize = page.size;
				
				let curTab = this.tabs[this.tabIndex];				
				
				
				if(this.tabIndex == 0){
					this.query.status = '1'
					delete this.query.expertIds
				}else{
					this.query.status = "2"
					this.query.expertIds = vk.getVuex('$user.userInfo.userId');
				}
				
				this.$util.request(this.$api.EvaluateList, this.query)
					.then(res => {
						// console.log('企业评分列表', res)
						//方法二(推荐): 后台接口有返回列表的总数据量 totalSize. 必传参数(当前页的数据个数, 总数据量)
						this.mescroll.endBySize(res.rows.length, res.total);
						//设置列表数据
						if (page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
						this.dataList = this.dataList.concat(res.rows); //追加新数据
					})
			},
			search(){
				this.query.companyName = this.keyword;
				this.mescroll.resetUpScroll();
			},
		}
	}
</script>

<style>
	@import url("/static/css/main.css");
	.calc_height_top {
		position: fixed;
		width: 100%;
		z-index: 99;
	}
</style>
